package com.accountbooks.justin;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.view.View;
import android.view.ViewGroup.LayoutParams;

public class TimeTag extends View {

	private Paint graphPaint = null;
	private Paint borderPaint = null;
	private Paint textPaint = null;
	private String text = null;
	private int width;
	private int height;
	
	public TimeTag(Context context, int width, int height, String text) {
		super(context);
		
		this.setLayoutParams(new LayoutParams(width, height));
		this.setFocusable(true);
		this.setFocusableInTouchMode(true);
		this.text = text;
		this.width = width;
		this.height = height;
		init();
	}

	private void init() {
		graphPaint = new Paint();
		graphPaint.setARGB(100, 0, 0, 0);
		graphPaint.setAntiAlias(true);
		graphPaint.setDither(true);
		graphPaint.setStyle(Style.FILL);
		
		borderPaint = new Paint();
		borderPaint.setARGB(100, 0, 0, 0);
		borderPaint.setAntiAlias(true);
		borderPaint.setDither(true);
		borderPaint.setStyle(Style.STROKE);
		borderPaint.setStrokeWidth(1);
		
		textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		textPaint.setTextSize(18);
		textPaint.setStrokeWidth(2);
		textPaint.setTextAlign(Align.RIGHT);
		textPaint.setSubpixelText(true);
		textPaint.setColor(Color.WHITE);
	}
	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		
		drawGraph(canvas);
		drawText(canvas);
	}

	private void drawGraph(Canvas canvas) {
		canvas.drawRect(0, 0, width, height, graphPaint);
		
		canvas.drawRect(0, 0, width, height, borderPaint);
	}
	
	private void drawText(Canvas canvas) {
		canvas.drawText(text, width - 10, 25, textPaint);
	}
}
